package org.aplombh.java.leetcode.all;

public class _9回文数 {
    public static void main(String[] args) {
        System.out.println(new Solution9_1().isPalindrome(1001));
    }
}

class Solution9_1 {
    public boolean isPalindrome(int x) {
        if (x < 0)
            return false;
        if (x < 10)
            return true;

        int len = 0;
        int t = x;

        while (t > 0) {
            len++;
            t = t / 10;
        }

        for (int i = 1, j = (int) Math.pow(10, len - 1); i < j; i *= 10, j /= 10) {
            if (((x / i) % 10) != ((x / j) % 10))
                return false;
        }
        return true;
    }
}

class Solution9_2 {
    public boolean isPalindrome(int x) {
        int sum = 0;
        int t = x;
        while (x > 0) {
            sum = x % 10 + 10 * sum;
            x /= 10;
        }
        return sum == t;
    }
}

class Solution9_3 {
    public boolean isPalindrome(int x) {
        if (x < 0 || (x % 10 == 0 && x != 0))
            return false;
        int sum = 0;
        int t = x;
        while (x > 0) {
            sum = x % 10 + 10 * sum;
            x /= 10;
        }
        return sum == t;
    }
}